#include <xp/bas/sysapi.h>
#include <xp/bas/string.h>
#include <xp/bas/stdio.h>

int xp_main ()
{
	int handle;
	xp_char_t tmpl[XP_PATH_MAX + 1];
	
#ifdef _WIN32
	xp_strcpy (tmpl, XP_TEXT("C:/opentmp-XXXXXX"));
#else
	xp_strcpy (tmpl, XP_TEXT("/tmp/opentmp-XXXXXX"));
#endif
	xp_printf (XP_TEXT("pid = %d\n"), xp_getpid());
	if ((handle = xp_opentmp(tmpl)) == -1) {
		xp_printf (XP_TEXT("cannot open temporary file\n"));
		return -1;
	}

	xp_printf (XP_TEXT("name: %s handle: %d\n"), tmpl, handle);

	xp_write (handle, "ABCD", 4);
	xp_close (handle);

	return 0;
}

